package cn.edu.neu.vmmigeval.io;

import java.io.File;
import java.io.FileWriter;

/**
 * Created by yfwz100 on 16/2/25.
 */
public class WriteUtil {


    public static void writeEnergyToFile(String url, double energy, double currentTimeOfAll) throws Exception {


        FileWriter fw = new FileWriter(url, true);
        String s = energy + "\t" + currentTimeOfAll + "\r\n";
        fw.write(s, 0, s.length());
        fw.flush();
        fw.close();

    }

    public static void writeSLAsToFile(String url, int times) throws Exception {

        FileWriter fw = new FileWriter(url, true);
        String s = times + "\r\n";
        fw.write(s, 0, s.length());
        fw.flush();
        fw.close();

    }

    public static void writeMigrationCostToFile(String url, double cost) throws Exception {

        FileWriter fw = new FileWriter(url, true);
        String s = cost + "\r\n";
        fw.write(s, 0, s.length());
        fw.flush();
        fw.close();

    }

    public static void writePowerToFile(String url, double energy) throws Exception {

        String str = url.substring(0, url.lastIndexOf("\\"));
        File f = new File(str);
        if (!f.exists()) {
            f.mkdirs();
        }
        FileWriter fw = new FileWriter(url, true);
        String s = energy + "\r\n";
        fw.write(s, 0, s.length());
        fw.flush();
        fw.close();

    }

    public static void writeCloudToFile(String url, double times) throws Exception {

        FileWriter fw = new FileWriter(url, true);
        String s = times + "\r\n";
        fw.write(s, 0, s.length());
        fw.flush();
        fw.close();

    }

    public static void writePDMToFile(String url, String times) throws Exception {

        String str = url.substring(0, url.lastIndexOf("\\"));
        File f = new File(str);
        if (!f.exists()) {
            f.mkdirs();
        }
        FileWriter fw = new FileWriter(url, true);
        String s = times;
        fw.write(s, 0, s.length());
        fw.flush();
        fw.close();

    }
/*public static void main(String[] args) throws Exception{

	String a = "C:\\Users\\queen\\Desktop\\data\\big\\cpu\\default\\pdm.txt";
	WriteUtil.writePDMToFile(a, "a");


}*/

    public static void writeMappingToFile(String url, String times) throws Exception {
        File f = new File(url);
        if (!f.exists()) {
            f.createNewFile();
        }
        FileWriter fw = new FileWriter(url, true);
        String s = times;
        fw.write(s, 0, s.length());
        fw.flush();
        fw.close();

    }

}
